import layoutHeaderAside from '@/layout/header-aside'
import layoutPage from '@/layout'

// 由于懒加载页面太多的话会造成webpack热更新太慢，所以开发环境不使用懒加载，只有生产环境使用懒加载
const _import = require('@/libs/util.import.' + process.env.NODE_ENV)

/**
 * 在主框架内显示
 */
const frameIn = [{
  path: '/',
  redirect: {
    name: 'index'
  },
  component: layoutHeaderAside,
  children: [
    // 首页
    {
      path: 'index',
      name: 'index',
      meta: {
        auth: true
      },
      component: _import('system/index')
    },
    // 用户页面
    {
      path: 'users',
      name: 'users',
      component: layoutPage,
      redirect: {
        name: 'users-list'
      },
      children: [
        // 用户列表
        {
          path: 'list',
          name: 'users-list',
          meta: {
            auth: true,
            title: '用户管理'
          },
          component: _import('chinchilla/admin/users/list')
        }
      ]
    },
    // 角色页面
    {
      path: 'roles',
      name: 'roles',
      component: layoutPage,
      redirect: {
        name: 'roles-list'
      },
      children: [
        // 角色列表
        {
          path: 'list',
          name: 'roles-list',
          meta: {
            auth: true,
            title: '角色列表'
          },
          component: _import('chinchilla/admin/roles/list')
        }
      ]
    },
    // 订单页面
    {
      path: 'orders',
      name: 'orders',
      component: layoutPage,
      redirect: {
        name: 'orders-list'
      },
      children: [
        // 订单列表
        {
          path: 'list',
          name: 'orders-list',
          meta: {
            auth: true,
            title: '订单列表'
          },
          component: _import('chinchilla/orders/list')
        }
      ]
    },
    // 房型页面
    {
      path: 'room-types',
      name: 'room-types',
      component: layoutPage,
      redirect: {
        name: 'room-types-list'
      },
      children: [
        // 房型列表
        {
          path: 'list',
          name: 'room-types-list',
          meta: {
            auth: true,
            title: '房型列表'
          },
          component: _import('chinchilla/admin/room-types/list')
        }
      ]
    },
    // 房间页面
    {
      path: 'rooms',
      name: 'rooms',
      component: layoutPage,
      redirect: {
        name: 'rooms-list'
      },
      children: [
        // 房间列表
        {
          path: 'list',
          name: 'rooms-list',
          meta: {
            auth: true,
            title: '房间列表'
          },
          component: _import('chinchilla/admin/rooms/list')
        }
      ]
    },
    // 设施页面
    {
      path: 'facilities',
      name: 'facilities',
      component: layoutPage,
      redirect: {
        name: 'facilities-list'
      },
      children: [
        // 设施列表
        {
          path: 'list',
          name: 'facilities-list',
          meta: {
            auth: true,
            title: '设施列表'
          },
          component: _import('chinchilla/admin/facilities/list')
        }
      ]
    },
    // 系统 前端日志
    {
      path: 'log',
      name: 'log',
      meta: {
        title: '前端日志',
        auth: true
      },
      component: _import('system/log')
    },
    // 刷新页面 必须保留
    {
      path: 'refresh',
      name: 'refresh',
      hidden: true,
      component: _import('system/function/refresh')
    },
    // 页面重定向 必须保留
    {
      path: 'redirect/:route*',
      name: 'redirect',
      hidden: true,
      component: _import('system/function/redirect')
    }
  ]
}]

/**
 * 在主框架之外显示
 */
const frameOut = [
  // 登录
  {
    path: '/login',
    name: 'login',
    component: _import('system/login')
  }
]

/**
 * 错误页面
 */
const errorPage = [{
  path: '*',
  name: '404',
  component: _import('system/error/404')
}]

// 导出需要显示菜单的
export const frameInRoutes = frameIn

// 重新组织后导出
export default [
  ...frameIn,
  ...frameOut,
  ...errorPage
]
